package cc.angis.xiugallery;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import cc.angis.xiugallery.common.GlobalConst;
import cc.angis.xiugallery.image.ui.ImageGridFragment;

import com.actionbarsherlock.app.SherlockListFragment;

public class SettingsFragment extends SherlockListFragment{
	
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		return inflater.inflate(R.layout.list, null);
	}

	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		SampleAdapter adapter = new SampleAdapter(getActivity());
//		for (int i = 0; i < 20; i++) {
//			adapter.add(new SampleItem(new  android.support.v4.app.Fragment(), "Sample List", android.R.drawable.btn_star));
//		}
		adapter.add(new SampleItem( this.getString(R.string.settings_account), R.drawable.ic_launcher));
		
		setListAdapter(adapter);
	}
	
	private class SampleItem {
		public String tag;
		public int iconRes;
		public SampleItem( String tag, int iconRes) {
			this.tag = tag; 
			this.iconRes = iconRes;
		}
	}

	public class SampleAdapter extends ArrayAdapter<SampleItem> {

		public SampleAdapter(Context context) {
			super(context, 0);
		}

		public View getView(final int position, View convertView, ViewGroup parent) {
			if (convertView == null) {
				convertView = LayoutInflater.from(getContext()).inflate(R.layout.row, null);
			}
			ImageView icon = (ImageView) convertView.findViewById(R.id.row_icon);
			TextView title = (TextView) convertView.findViewById(R.id.row_title);
			icon.setImageResource(getItem(position).iconRes);
			title.setText(getItem(position).tag);
			return convertView;
		}

	}

	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		switch (position) {
			case 0:
				Intent i = new Intent(getActivity(), UserAccountActivity.class);
				getActivity().startActivity(i);
				break;
			default:
				break;
		}
		super.onListItemClick(l, v, position, id);
	}

}
